var mongoose = require("mongoose");
// var DB_URL = "mongodb://mydb:Kh5nEH5y8EsXsP6H@127.0.0.1:27017/mydb";
var DB_URL = "mongodb://127.0.0.1:27017/mydb";


mongoose.connect(DB_URL, { useNewUrlParser: true, useUnifiedTopology: true, useCreateIndex: true });
//状态的监听
mongoose.connection.on("connected", function () {
    console.log("mongoDB连接成功");
});
mongoose.connection.on("error", function (err) {
    console.log(err);
});
mongoose.connection.on("disconnected", function () {
    console.log("mongoDB连接断开");
});
//导出方便其他地方使用
//commonjs
module.exports = mongoose;
